package com.wantup.demo03xd.part05.communication.demo;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/7/3 14:51
 * <p>
 * <p>
 * 线程间通信
 */
public class Demo {

    private static volatile boolean flag = false;

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (!flag) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("flag is false");
                }
                System.out.println("flag is true");

            }
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new Thread(() -> {
            flag = true;
        }).start();


    }


}
